-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
virtme-ng: Set a default for --name #34
Conversation
I've been thinking to do something like this in the past, but one issue that I've found changing the hostname by default is that some commands may complain about the hostname change, for example:
This doesn't happen if the hostname is identical, so that's why by default I decided to not change the hostname, but provide the Also this is the reason why now we're printing the virtme-ng banner at boot, so at least we can see that a virtme-ng session has started, otherwise it would be very confusing to distinguish between host and guest. Maybe we should try to set something in the bash prompt? Like adding some a "virtme-ng" string somewhere to the PS1 env variable when the virtme-ng session is started? |
Hmm, are there other instances of things that a changed hostname causes problems with? On my system I don't see that behavior, so I wonder if it might be some distro configuration or version-specific sudo behavior that we could just add a little workaround for if it's just that...
My sudo version, FWIW:
Maybe something like this in virtme-ng-init? diff --git a/src/main.rs b/src/main.rs
index a436b2c83f33..415607cae673 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -317,10 +317,21 @@ fn generate_sudoers() -> io::Result<()> {
Ok(())
}
+fn generate_hosts() -> io::Result<()> {
+ if let Ok(hostname) = env::var("virtme_hostname") {
+ std::fs::copy("/etc/hosts", "/tmp/hosts")?;
+ let mut h = OpenOptions::new().write(true).append(true).open("/tmp/hosts")?;
+ writeln!(h, "127.0.0.1 {}\n::1 {}", hostname, hostname)?;
+ utils::do_mount("/tmp/hosts", "/etc/hosts", "", libc::MS_BIND as usize, "");
+ }
+ Ok(())
+}
+
fn override_system_files() {
generate_fstab().ok();
generate_shadow().ok();
generate_sudoers().ok();
+ generate_hosts().ok();
} Or possibly just some other little bit of |
....
Adjusting With that in place I'll be happy to apply also this PR, thanks! |
Sure, init PR here: arighi/virtme-ng-init#4 I figure once that's merged I'll add a commit to this branch doing both a submodule update to incorporate that and the corresponding virtme-init tweak to make it a single atomic change. |
Applied and ran all my usual tests also with this PR applied, all good!
Sure, go for it, I was thinking to resync the virtme-ng-init submodule anyway, so we can do it with this PR since we need the hostname change. Thank you so much for working on this, showing |
The update of the virtme_ng_init submodule pulls in a larger batch of changes; while most of them are non-behavioral code cleanups, also included is commit a1eb25c ("Add guest hostname to /etc/hosts"), which makes the corresponding change to this one so that the two inits remain behaviorally in sync with each other. Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
e232348
to
210910f
Compare
This is basically just to help make it easier to distinguish a shell prompt within the guest from one on the host (as long as your prompt incorporates the hostname). Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
210910f
to
81e8d82
Compare
Sure, no problem -- now updated with all of the above. |
Applied, thanks, this one is really useful! |
With virtme-ng defaulting to running as the current user instead of root, I've been finding it easy to get confused about whether my shell prompt (which includes the hostname) is from the host or the guest (since they end up identical). Providing a recognizable default for the
--name
flag makes it easier to tell them apart.